#账户序号
AccountIndex=-1

#账户集合
accountList=[
    {'username':'zhangsan','passwd':'123456','money':1000},
    {'username':'lisi','passwd':'123456','money':500},
    {'username':'wangwu','passwd':'123456','money':4000}]


#验证账户
def showAccount(username,passwd):
    for i in range(len(accountList)):
        if username==accountList[i]['username'] and passwd==accountList[i]['passwd']:
            accountIndex=i
            showMenu()
        
    if accountIndex==-1:
        print("="*20,"账户不存在或密码错误","="*20)
        str=input("是否继续操作？(Y/N)")
        isSURE(str)
        
#确认输入
def isSURE(str):
    if(str=='Y' or str=='y'):
        login()
    elif(str=='N' or str=='n'):
        print("="*20,"谢谢使用，再见！","="*20)
        return
    else:
        isSURE(input("非法输入！是否继续操作？(Y/N)"))

#登录
def login():
    uname=input("请输入账号：")
    pwd=input("请输入密码：")
    showAccount(uname,pwd)

#操作菜单及退出
def showMenu():
    print("="*16,"请选择所需的操作","="*16)
    print("{0:1} {1:13} {2:15}".format(" ","1. 查询余额","2. 取钱"))
    print("{0:1} {1:13} {2:15}".format(" ","3. 存钱","4. 退出系统"))
    print("="*50)
    key = input("请输入对应的选择：")
    if(key=='1'):
        queryMoney()
        showMenu()
        
    elif(key=='2'):
        delMoney()
        
    elif(key=='3'):
        addMoney()
        
    elif(key=='4'):
        print("="*20,"谢谢使用，再见！","="*20)
    
    else:
        print('非法输入！')
        showMenu()

#查询余额
def queryMoney():
    print('当前余额为：',accountList[AccountIndex]['money'])
    showMenu()

#存钱
def addMoney():
    num = input("请输入存款数：")
    if(num.isdigit()): 
        accountList[AccountIndex]['money']+=int(num)
        queryMoney()
    else:
         print("输入的不是数字！")
         showMenu()    

#取钱
def delMoney():
    num = input("请输入存款数：")
    if(num.isdigit()): 
        if accountList[AccountIndex]['money']<int(num):
            print("余额不足，取款失败！")
            queryMoney()
        accountList[AccountIndex]['money']-=int(num)
        queryMoney()
    else:
         print("输入的不是数字！")
         showMenu()    


login()
